package baiqitun.stupro.project.service.impl;

import baiqitun.stupro.common.exception.enums.support.NotFoundExceptionEnum;
import baiqitun.stupro.common.exception.support.NotFoundException;
import baiqitun.stupro.common.exception.support.RelationExistedException;
import baiqitun.stupro.common.service.support.MongoServiceImpl;
import baiqitun.stupro.project.entity.SysProjectBrowse;
import baiqitun.stupro.project.entity.SysProjectLike;
import baiqitun.stupro.project.service.SysProjectBrowseService;
import baiqitun.stupro.project.service.SysProjectService;
import baiqitun.stupro.security.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目浏览记录业务类
 * @author kedaji
 */
@Service
public class SysProjectBrowseServiceImpl extends MongoServiceImpl<SysProjectBrowse> implements SysProjectBrowseService {
    @Autowired
    private SysProjectService sysProjectService;
    @Autowired
    private SysUserService sysUserService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void browse(String userId, String projectId, String createBy) {
        sysProjectService.checkNotFound(projectId, new NotFoundException(NotFoundExceptionEnum.PROJECT_NOT_FOUND));
        sysUserService.checkEnabled(userId);
        SysProjectBrowse queryProjectLike = new SysProjectBrowse();
        queryProjectLike.setUserId(userId).setProjectId(projectId).setCreateBy(createBy);
        save(queryProjectLike);
    }
}
